/*
 * File:   CharacterServiceImpl.cpp
 * Author: luk
 *
 * Created on March 1, 2015, 9:37 PM
 */

#include <math.h>

#include "CharacterServiceImpl.h"

DiceAdds getThrustingDamage(int strength) {
    if (strength > 20) {
        return getThrustingDamage(20);
    } else {
        switch (strength) {
            case 1:
                return DiceAdds(1, -6);
            case 2:
                return DiceAdds(1, -6);
            case 3:
                return DiceAdds(1, -5);
            case 4:
                return DiceAdds(1, -5);
            case 5:
                return DiceAdds(1, -4);
            case 6:
                return DiceAdds(1, -4);
            case 7:
                return DiceAdds(1, -3);
            case 8:
                return DiceAdds(1, -3);
            case 9:
                return DiceAdds(1, -2);
            case 10:
                return DiceAdds(1, -2);
            case 11:
                return DiceAdds(1, -1);
            case 12:
                return DiceAdds(1, -1);
            case 13:
                return DiceAdds(1, 0);
            case 14:
                return DiceAdds(1, 0);
            case 15:
                return DiceAdds(1, 1);
            case 16:
                return DiceAdds(1, 1);
            case 17:
                return DiceAdds(1, 2);
            case 18:
                return DiceAdds(1, 2);
            case 19:
                return DiceAdds(2, -1);
            case 20:
                return DiceAdds(2, -1);
            default:
                return DiceAdds(0, 0);
        }
    }
}

DiceAdds getSwingingDamage(int strength) {
    if (strength > 20) {
        return getSwingingDamage(20);
    } else {
        switch (strength) {
            case 1:
                return DiceAdds(1, -5);
            case 2:
                return DiceAdds(1, -5);
            case 3:
                return DiceAdds(1, -4);
            case 4:
                return DiceAdds(1, -4);
            case 5:
                return DiceAdds(1, -3);
            case 6:
                return DiceAdds(1, -3);
            case 7:
                return DiceAdds(1, -2);
            case 8:
                return DiceAdds(1, -2);
            case 9:
                return DiceAdds(1, -1);
            case 10:
                return DiceAdds(1, 0);
            case 11:
                return DiceAdds(1, 1);
            case 12:
                return DiceAdds(1, 2);
            case 13:
                return DiceAdds(2, -1);
            case 14:
                return DiceAdds(2, 0);
            case 15:
                return DiceAdds(2, 1);
            case 16:
                return DiceAdds(2, 2);
            case 17:
                return DiceAdds(3, -1);
            case 18:
                return DiceAdds(3, 0);
            case 19:
                return DiceAdds(3, 1);
            case 20:
                return DiceAdds(3, 2);
            default:
                return DiceAdds(0, 0);
        }
    }
}

Character CharacterServiceImpl::create(Attribute attribute) {
    float basicLift = attribute.getStrength() * attribute.getStrength() / 5.0f;
    if (basicLift >= 10.0f) {
        basicLift = round(basicLift);
    }

    float basicSpeed = (attribute.getDexterity() + attribute.getHealth()) / 4.0f;

    return Character(attribute, Characteristic(
            basicLift,
            basicSpeed,
            basicSpeed,
            attribute.getHealth(),
            attribute.getStrength(),
            attribute.getIntelligence(),
            attribute.getIntelligence(),
            getThrustingDamage(attribute.getStrength()),
            getSwingingDamage(attribute.getStrength())));
}
